function compute()
{
	var select = document.getElementById("ease");
	var funcName = select.value;
	var func = eval( funcName );
	var start = parseInt( document.getElementById("start").value );
	var end = parseInt( document.getElementById("end").value );
	var max = parseInt( document.getElementById("numIterations").value );
	var tab = tweenCompute( start, end, func, max );
	return tab;
}

function onEditorSubmit()
{
	var values = compute();
	
	displayTab( values );
	drawCourb( values );
	
	return false;
}

function displayTab( p_values )
{
	var results = document.getElementById("results");
	var content = "<table>";
	var max = p_values.length;
	var i = 0;
	
	content += "<tr>";
	
	for( i = 0; i < max; i++ )
	{
		content += "<th>"+i+"</th>";
	}
	
	content += "</tr>";
	content += "<tr>";
	
	for( i = 0; i < max; i++ )
	{
		content += "<td>"+p_values[i]+"</td>";
	}
	
	content += "</tr>";
	content += "</table>";
	
	results.innerHTML = content;
	
}

function drawCourb( p_values )
{
	var canvas = document.getElementById("mycanvas");
	var context = canvas.getContext("2d");
	var width = parseInt( canvas.width );
	var height = parseInt( canvas.height );
	var max = p_values.length;
	var i = 0;
	var midY = ( height * 0.5 ) >> 0;
	var stepX = parseInt( width / max );
	var ratioY = midY / p_values[p_values.length - 1];
	
	context.clearRect( 0, 0, width, height );
	context.fillStyle = "black";
	context.fillRect( 0, 0, width, height);
	context.strokeStyle = "green";
	context.lineWidth = 2;
	context.beginPath();
	context.moveTo(0,0);
	
	for( i = 0; i < max; i++ )
	{
		context.lineTo( stepX * i ,  midY - ( p_values[i] * ratioY ) );
	}
	
	context.stroke();
}


function genBuildingConfig( 	
								/*easing function*/
								p_ease,
								/*cost*/
								p_costGoldStart, p_costGoldEnd, 
								p_costManaStart, p_costManaEnd, 
								p_costGemsStart, p_costGemsEnd, 
								p_costSenatStart, p_costSenatEnd, 
								/*prod*/
								p_prodGoldStart, p_prodGoldEnd, 
								p_prodManaStart, p_prodManaEnd,
								/*evolution*/
								p_evolutionStart,p_evolutionEnd,
								/*levels*/
								p_numLevels
)
{
	var config = new Object();
	
	config.costGold = tweenCompute( p_costGoldStart, p_costGoldEnd, p_ease, p_numLevels );
	config.prodGold = tweenCompute( p_prodGoldStart, p_prodGoldEnd, p_ease, p_numLevels );
	
	config.costMana = tweenCompute( p_costManaStart, p_costManaEnd, p_ease, p_numLevels );
	config.prodMana = tweenCompute( p_prodManaStart, p_prodManaEnd, p_ease, p_numLevels );
	
	config.costGems = tweenCompute( p_costGemsStart, p_costGemsEnd, p_ease, p_numLevels );
	config.costSenat = tweenCompute( p_costSenatStart, p_costSenatEnd, p_ease, p_numLevels );
	
	config.evolutionTime = tweenCompute( p_evolutionStart, p_evolutionEnd, p_ease, p_numLevels );
	
	return config;
}
